﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;

namespace DC.Views
{
    public partial class Form_AddRange : Skin_DevExpress
    {
        public Form_AddRange()
        {
            InitializeComponent();
        }
        public List<int> range = new List<int>();
        public bool issuccess = false;
        Utils.Database DB = Utils.Global.GlobalDB;

        private void Form_AddRange_Load(object sender, EventArgs e)
        {
            string sql = "select distinct(Project_Father) from Project";
            DataView dv = DB.GetDs(sql).Tables[0].DefaultView;
            for (int i = 0; i < dv.Count; i++)
            {
                if (dv[i][0].ToString()==String.Empty)
                {
                    continue;
                }
                comboBox1.Items.Add(dv[i][0].ToString());
            }
            comboBox1.SelectedIndex = 0;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sql = "select Project_ID,Project_Name from Project where Project_Father='" + comboBox1.Text + "'";
            DataView dv = DB.GetDs(sql).Tables[0].DefaultView;
            listView1.Items.Clear();
            listView1.BeginUpdate();
            for (int i = 0; i < dv.Count; i++)
            {
                ListViewItem item = new ListViewItem();
                item.Tag = dv[i][0].ToString();
                item.Text = dv[i][1].ToString();
                item.Checked = false;
                listView1.Items.Add(item);
            }
            listView1.EndUpdate();
        }

        private void skinButton4_Click(object sender, EventArgs e)
        {
            if (listView1.CheckedItems.Count == 0)
            {
                MessageBox.Show("没有选择项目，请选中多个项目！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            for (int i = 0; i < listView1.CheckedItems.Count; i++)
            {
                range.Add(Convert.ToInt32(listView1.CheckedItems[i].Tag.ToString()));
            }
            issuccess = true;
            Close();
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                listView1.Items[i].Checked = true;
            }
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                listView1.Items[i].Checked = false;
            }
        }

        private void skinButton3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                listView1.Items[i].Checked = !listView1.Items[i].Checked;
            }
        }
    }
}
